#ifndef INPUT_MANAGER_H
#define INPUT_MANAGER_H

#include <dinput.h>
#include <time.h>
#include <d3d9.h>
#include <d3dx9.h>

#pragma comment (lib,"d3d9.lib")
#pragma comment (lib,"d3dx9.lib")
#pragma comment (lib,"dinput8.lib")
#pragma comment (lib,"dxguid.lib")

#define TIME_TO_LONG_CLICK 50
#define TIME_TO_DOUBLE_CLICK 200
#define DISTANCE_TO_DRAG 25

enum Mouse_Gestures
{
	LongClick=0,
	DoubleClick,
	Drag
};

class InputManager
{
private:
	
	LPDIRECTINPUT8 din;
	LPDIRECTINPUTDEVICE8 dinKeyboard;
	LPDIRECTINPUTDEVICE8 dinMouse;
	DIMOUSESTATE mouseState;
	DIMOUSESTATE oldMouseState;

	BYTE keyState[256];
	BYTE oldKeyState[256];

	DWORD mouseDownTime[4];
	DWORD mouseUpTime[4];
	int mouseDownTimeCount[4];
	D3DXVECTOR2 mousePos;
	D3DXVECTOR2 oldMousePos;

	bool startDetectionDoubleClick;
	bool clamptoScreen;
	
	float distanceVector(D3DXVECTOR2 vector1,D3DXVECTOR2 vector2);
	void setMousePosition();
public:
	InputManager();
	void initDInput(HINSTANCE hInstance, HWND hWnd);
	void detectInput(void);
	void cleanDInput(void);
	void Update(int dt);
	bool isKeyPressed(byte key);
	bool isKeyReleased(byte key);
	bool wasKeyPressed(byte key);
	bool wasKeyReleased(byte key);
	bool isButtonPressed(byte button);
	bool wasButtonPressed(byte button);
	bool wasButtonReleased(byte button);
	bool getGesture(int type);
	void copyOldStates();
	void changeMouseTimeUpOrDown(byte button);
	D3DXVECTOR2 getDeltaMouse();
};
#endif